package com.zjwd.web.controller.basic;

import com.zjwd.basic.domain.BasicIpc;
import com.zjwd.basic.service.IBasicIpcService;
import com.zjwd.common.annotation.Log;
import com.zjwd.common.core.controller.BaseController;
import com.zjwd.common.core.domain.AjaxResult;
import com.zjwd.common.core.page.TableDataInfo;
import com.zjwd.common.enums.BusinessType;
import com.zjwd.common.utils.poi.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 基础中期支付证书Controller
 *
 * @author liquan
 * @date 2024-12-09
 */
@RestController
@RequestMapping("/basic/ipc")
public class BasicIpcController extends BaseController {

    @Autowired
    private IBasicIpcService service;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('basic:ipc:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicIpc model) {
        startPage();
        List<BasicIpc> list = service.selectModelList(model);
        return getDataTable(list);
    }

    /**
     * 支付项目下拉选项
     * 不包含传递过来的支付项目
     *
     * @param itemCode 项目编号
     * @return 结果
     */
    @GetMapping("/selectDropDownOptionsNotSelf")
    public AjaxResult selectDropDownOptionsNotSelf(String itemCode) {
        List<BasicIpc> list = service.selectDropDownOptionsNotSelf(itemCode);
        return AjaxResult.success(list);
    }

    /**
     * 导出
     */
    @PreAuthorize("@ss.hasPermi('basic:ipc:export')")
    @Log(title = "基础中期支付证书", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BasicIpc model) {
        List<BasicIpc> list = service.selectModelList(model);
        ExcelUtils<BasicIpc> util = new ExcelUtils<BasicIpc>(BasicIpc.class);
        return util.exportExcel(list, "基础中期支付证书数据");
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:ipc:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(service.getModelById(id));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('basic:ipc:add')")
    @Log(title = "基础中期支付证书", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicIpc model) {
        return toAjax(service.insert(model));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('basic:ipc:edit')")
    @Log(title = "基础中期支付证书", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicIpc model) {
        return toAjax(service.update(model));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('basic:ipc:remove')")
    @Log(title = "基础中期支付证书", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(service.deleteByIds(ids));
    }
}
